package com.xl.qa.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xl.dao.domain.XlQuestionOrder;
import com.xl.dao.mapper.XlQuestionOrderMapper;
import com.xl.qa.enmus.QuestionOrderStateEnums;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author 钟勇
 * Create in 2024/1/23 13:17
 */
@Component
@RequiredArgsConstructor
public class QuestionOrderPayJob {

    private final XlQuestionOrderMapper orderMapper;

    /**
     * 每小时执行一次，订单支付超时处理
     */
    @Scheduled(cron = "0 0 0/1 * * ?")
    public void paymentTimeout() {
        orderMapper.update(new XlQuestionOrder()
                        .setOrderState(QuestionOrderStateEnums.paymentTimeout.getState())
                , new LambdaQueryWrapper<XlQuestionOrder>()
                        .eq(XlQuestionOrder::getState, 1)
                        .eq(XlQuestionOrder::getOrderState, QuestionOrderStateEnums.add.getState())
                        .le(XlQuestionOrder::getPayValidTime, LocalDateTime.now())
        );
    }

}
